// <copyright file="AuthorisationPolicyUsernamePasswordValidator.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Barry Dorrans</author>
// <email>barryd@idunno.org</email>
// <date>2008-06-10</date>
// <summary>Contains a WCF username/password validator which forwards the validation to the
// authorisation policy provider.</summary>

namespace SharpSTS
{
    using System.IdentityModel.Selectors;
    using System.IdentityModel.Tokens;
    using Properties;
    using Providers;

    /// <summary>
    /// Authenticates an username / password combination through the authorisation policy provider
    /// </summary>
    public class AuthorisationPolicyUserNamePasswordValidator : UserNamePasswordValidator
    {
        /// <summary>
        /// When overridden in a derived class, validates the specified username and password.
        /// </summary>
        /// <param name="userName">The username to validate.</param>
        /// <param name="password">The password to validate.</param>
        public override void Validate(string userName, string password)
        {
            if (!AuthorisationPolicyManager.AuthenticateUserNamePassword(userName, password))
            {
                throw new SecurityTokenException(Resources.ErrorFailedToAuthenticateUser);
            }
        }
    }
}
